define(function (require, exports, module) {

    exports.init = function () {
        //用户点击重置按钮
        $("#myreset").on("click", function () {
            myReset();
        });
        //用户点击提交按钮
        $("#mysubmit").on("click", function () {
            mySubmit();
        });
    };
});

function myReset() {
    $("#accountField").val("");
    $("#passwordField").val("");
}

function mySubmit() {
    //var account = document.getElementById("accountField").value;
    var index;
    var $account = $("#accountField").val();
    if ($account == null || $account == "") {
        //alert("账号不能为空");
        //第三方插件 弹出框
        sweetAlert("账号不能为空!", "", "error");
        return;
    } else if ($account.replace(/(^\s+)|(\s+$)/g, "").length == 0) { /*类似string.trim().length==0*/
        //alert("账号不能为空");
        sweetAlert("账号不能为空!", "", "error");
        return;
    }
    $account = $account.replace(/(^\s+)|(\s+$)/g, "");

    //var password = document.getElementById("passwordField").value;
    var $password = $("#passwordField").val();
    if ($password == null || $password == "") {
        //alert("密码不能为空");
        sweetAlert("密码不能为空!", "", "error");
        return;
    } else if ($password.replace(/(^\s+)|(\s+$)/g, "").length == 0) {
        //alert("密码不能为空");
        sweetAlert("密码不能为空!", "", "error");
        return;
    } else {
        /* 第三方插件：layer提示框*/
        index = layer.msg('登录中...', {icon: 16});
    }
    $password = $password.replace(/(^\s+)|(\s+$)/g, "");

    /*alert("账号:"+$account+"/密码:"+$password);*/
    $.post("user/UserController/login", {account: $account, password: $password}, function (result) {

        /*alert("result:"+result.STATUS);*/
        if (result.STATUS == "SUCCESS") {
            setTimeout(function () {
                //两秒后关闭layer层
                layer.close(index);
                /*alert("相等的");*/
                window.location.href = "user/UserController/main";
            }, 2000);

        } else {
            /*alert("登录失败");*/
            var $myError = $("#myError");
            $myError.text(result.FAIL_MESSAGE);
            $myError.css("display", "block");
        }
    });

}